#pragma once
#include <iostream>
using namespace std;
#include <pthread.h>
class Mutex
{
public:
    Mutex(pthread_mutex_t* mutex = nullptr)
    :mutex_p(mutex)
    {}
    ~Mutex(){}
    void lock()
    {
        if(mutex_p)pthread_mutex_lock(mutex_p);
    }
    void unlock()
    {
        if(mutex_p)pthread_mutex_unlock(mutex_p);
    }
private:
    pthread_mutex_t* mutex_p;
};

class LockGuard
{
public:
    LockGuard(pthread_mutex_t* mutex)
    :mutex_(mutex)
    {
        mutex_.lock();
    }
    ~LockGuard(){
        mutex_.unlock();
    }
private:
    Mutex mutex_;
};
